# -*- encoding=utf8 -*-
__author__ = "yangxianming"

from airtest.core.api import *
# ST.PROJECT_ROOT = "E:\AirtestWorkSpace\fuyuanwaiUItest"
# using(r"E:\AirtestWorkSpace\fuyuanwaiUItest\common.air")
# from common import *

auto_setup(__file__)

#拿到设备编号
import sys
args = sys.argv
devicePid = args[4].split("/")[3]
print("--------" + devicePid)
rootArr = args[2].split("\\")
scriptRoot = ""
for i in range(len(rootArr) - 1):
    scriptRoot = scriptRoot + rootArr[i] + "\\"
print("--------" + scriptRoot)

#对更目录下设变编号文件做注册登记操作 1代表在使用  0代表停止使用
with open(scriptRoot + devicePid, 'w') as f:
    f.write('1')
    
using(scriptRoot + "common.air")
from common import *
stop_app("com.alibaba.android.rimet")
start_app("com.alibaba.android.rimet")

try:

    sleep(1.0)
    openKoufu()
    sleep(1.0)
    openScene("weiyitong")
    
    ##微医因为无法循环购买医疗权益，只验证产品是否存在，价格是否准确即可
    #后期如果可以删除数据完成测试闭环再丰富脚本
    sleep(5.0)
    #点击月卡
    touch(Template(r"tpl1682044390066.png", resolution=(1080, 1920)))
    sleep(1.0)
    assert_exists(Template(r"tpl1681116389017.png", record_pos=(-0.317, 0.801), resolution=(1080, 1920)), "月卡每月28元")
    sleep(1.0)
    keyevent("BACK")
    #点击年卡
    touch(Template(r"tpl1682044419411.png", resolution=(1080, 1920)))
    sleep(1.0)
    assert_exists(Template(r"tpl1681116477264.png", record_pos=(0.003, 0.367), resolution=(1080, 1920)), "年卡258元")
    sleep(5.0)
    
except Exception as e:
    print(e)
finally:
    sleep(1.0)
    stop_app("com.alibaba.android.rimet")
    #完成测试等级设备为0以便被其他脚本使用
    with open(scriptRoot + devicePid, 'w') as f:
        f.write('0')